<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf" %>
<!DOCTYPE html>
<html>
<head>
    <title>接口列表</title>
    <meta name="decorator" content="form"/>
    <html:css name="bootstrap-fileinput"/>
    <html:css name="simditor"/>
</head>

<body class="white-bg" formid="infcForm">
<form:form id="infcForm" modelAttribute="data" method="post" class="form-horizontal">
    <form:hidden path="id"/>
    <table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
        <tbody>
        <tr>
            <td class="width-15 active text-right">
                <label><font color="red">*</font>接口类别:</label>
            </td>
            <td class="width-35">
                <form:hidden path="typeId"/>
                <form:input path="typeName" htmlEscape="false" class="form-control" datatype="*" nullmsg="请填选择类别" readonly="true"/>
                <label class="Validform_checktip"></label>
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-right">
                <label><font color="red">*</font>接口编号:</label>
            </td>
            <td class="width-35">
                <form:input path="code" htmlEscape="false" class="form-control" datatype="*" nullmsg="请填写接口编号"
                            ajaxurl="${adminPath}/sys/infc/validate"/>
                <label class="Validform_checktip"></label>
            </td>
            <td class="width-15 active text-right">
                <label><font color="red">*</font>接口名称:</label>
            </td>
            <td class="width-35">
                <form:input path="name" htmlEscape="false" class="form-control" datatype="*"/>
                <label class="Validform_checktip"></label>
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-right">
                <label><font color="red">*</font>请求类型:</label>
            </td>
            <td class="width-35">
                <form:radiobuttons path="reqType" htmlEscape="false" class="form-control" dict="reqType"
                                   defaultValue="0" datatype="*" delimiter="&nbsp;&nbsp;" cssClass="i-checks required"/>
                <label class="Validform_checktip"></label>
            </td>
            <td class="width-15 active text-right">
                <label><font color="red">*</font>操作类型:</label>
            </td>
            <td class="width-35">
                <form:select  defaultValue="3"   path="operType" htmlEscape="false" class="form-control" dict="operType" datatype="*"/>
                <label class="Validform_checktip"></label>
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-right">
                <label><font color="red">*</font>使用设备:</label>
            </td>
            <td class="width-35">
                <form:checkboxes path="useEqp" delimiter="&nbsp;&nbsp;" htmlEscape="false" showValue="${useEqpList}"  defaultValue="1"  
                                 class="form-control" dict="useEqp" datatype="*" cssClass="i-checks required"/>
                <label class="Validform_checktip"></label>
            </td>
            <td class="width-15 active text-right">
                <label><font color="red">*</font>接口类型:</label>
            </td>
            <td class="width-35">
                <form:radiobuttons path="supportType" htmlEscape="false" class="form-control" dict="supportType"
                                   defaultValue="2" datatype="*" delimiter="&nbsp;&nbsp;" cssClass="i-checks required"/>
                <label class="Validform_checktip"></label>
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-right">
                <label>title:(饼图的title是动态的)</label>
            </td>
            <td class="width-35">
                <form:input path="title" htmlEscape="false" class="form-control"/>
                <label class="Validform_checktip"></label>
            </td>
            <td class="width-15 active text-right">
                <label><font color="red">*</font>图表类型:</label>
            </td>
            <td class="width-35">
                <form:select path="chartType" htmlEscape="false" class="form-control" dict="echartsReportType"/>
                <label class="Validform_checktip"></label>
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-center" colspan="4">
                xname 和 yname，若不填写，则从sql结果中获取，若这里设置了，则优先取这里设置的值
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-right">
                <label>xname:</label>
            </td>
            <td class="width-35">
                <form:input path="xname" htmlEscape="false" class="form-control"/>
                <label class="Validform_checktip"></label>
            </td>
            <td class="width-15 active text-right">
                <label>yname:</label>
            </td>
            <td class="width-35">
                <form:input path="yname" htmlEscape="false" class="form-control"/>
                <label class="Validform_checktip"></label>
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-right">
                <label>柱子宽度:</label>
            </td>
            <td class="width-35">
                <form:input path="barWidth" htmlEscape="false" class="form-control"/>
                <label class="Validform_checktip"></label>
            </td>
            <td class="width-15 active text-right">
                <label>返回类型:</label>
            </td>
            <td class="width-35" colspan="3">
                <form:radiobuttons path="returnType" htmlEscape="false" class="form-control" dict="ReturnType"
                                   defaultValue="1" datatype="*" delimiter="&nbsp;&nbsp;" cssClass="i-checks required"/>
                <label class="Validform_checktip"></label>
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-center" colspan="4">
                接口地址 和 自定义sql只能填写其中一项，占位符使用${'${'}key}
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-right">
                <label>接口地址:</label>
            </td>
            <td class="width-35" colspan="3">
                <form:input path="interfaceUrl" htmlEscape="false" class="form-control"/>
                <label class="Validform_checktip"></label>
            </td>

        </tr>
        <tr>
            <td class="width-15 active text-right">
                <label>定义sql:</label>
            </td>
            <td class="width-35" colspan="3">
                <form:textarea path="definedSql" htmlEscape="false" class="form-control" style="min-height:280px;"/>
                <label class="Validform_checktip"></label>
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-right">
                <label>请求body:</label>
            </td>
            <td class="width-35" colspan="3">
                <form:textarea path="reqBody" htmlEscape="false" class="form-control"/>
                <label class="Validform_checktip"></label>
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-right">
                <label>成功时返回消息:</label>
            </td>
            <td class="width-35" colspan="3">
                <form:textarea path="sucMsg" htmlEscape="false" class="form-control"/>
                <label class="Validform_checktip"></label>
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-right">
                <label>失败时返回消息:</label>
            </td>
            <td class="width-35" colspan="3">
                <form:textarea path="failMsg" htmlEscape="false" class="form-control"/>
                <label class="Validform_checktip"></label>
            </td>
        </tr>
        <tr>
            <td class="width-15 active text-right">
                <label>备注:</label>
            </td>
            <td class="width-35" colspan="3">
                <form:textarea path="remark" htmlEscape="false" class="form-control"/>
                <label class="Validform_checktip"></label>
            </td>
        </tr>

        </tbody>
    </table>
</form:form>
<html:js name="bootstrap-fileinput"/>
<html:js name="simditor"/>
<script type="text/javascript">

    /**
     * 检查sql安全性，禁止所有能修改数据库的关键字
     * @returns {boolean} true：检查通过返，false：检查不通过
     */
    function checkSql() {
        var definedSql = $('#definedSql').val();
        if (definedSql !== '') {
            var reg = /(update|delete|insert|trancate|into|declare|drop|execute|alter|modify|change)/i;
            return !reg.test(definedSql);
        }
        return true;
    }

    function beforeSubmit() {
        var interfaceUrl = $('#interfaceUrl').val();
        var definedSql = $('#definedSql').val();
        if (!checkSql()) {
            top.layer.msg("SQL不合法！" , {icon: 2});
            return false;
        }
        if(interfaceUrl === '' && definedSql === '') {
            top.layer.msg("报表url 或 报表sql，必填一项！" , {icon: 2});
            return false;
        }
        return true;
    }
    /**
     * @description 关闭layer的加载层.<br>
     * @returns 返回打开的阴影层的下标.<br>
     * @author zcg.<br>
     */
    function closeLoad(index){
        top.layer.close(index);
        top.layer.closeAll('loading');
    }

    /**
     * @param description .<br>
     * @author zcg .<br>
     * @date 2017/1/19 .<br>
     */
    function changeSupport(value) {
        if (value == 1) {
            $('#interfaceUrl').attr("ignore", false);
            $('#definedSql').attr("ignore", true);
            $('#interfaceUrl').attr("datatype", "*");
            $('#definedSqlTr').removeAttr("datatype", "*");
            $('#definedSqlTr').hide();
            $('#interfaceUrlTr').show();
        } else {
            $('#interfaceUrl').attr("ignore", true);
            $('#definedSql').attr("ignore", false);
            $('#definedSqlTr').attr("datatype", "*");
            $('#interfaceUrl').removeAttr("datatype", "*");
            $('#definedSqlTr').show();
            $('#interfaceUrlTr').hide();
        }
    }
</script>
</body>
</html>